<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
?>

<?php
$instructor_id = mysql_real_escape_string(strip_tags($_GET['id']));
$q = "SELECT * FROM instructors WHERE id = '$instructor_id'";
$r = mysql_query($q);
$row = mysql_fetch_assoc($r);
$instructor_fname = $row['first_name'];
$instructor_lname = $row['last_name'];


//$query = "SELECT * FROM instructors WHERE id = '$instructor_id'";
//$result = mysql_query($query);
//$instructor_fname = mysql_result($result,0,"first_name");
//$instructor_lname = mysql_result($result,0,"last_name");

?>
<p><a href="index.php">&lt;&lt; Back to Instructors Portal</a></p>
<h1><?php echo $instructor_fname.' '.$instructor_lname; ?> Timeslots</h1>
<p><a href="add_timeslots.php?iid=<?php echo $instructor_id; ?>">Add timeslot</a></p>
<?php


//select statement
$query = "SELECT * FROM instructor_availability WHERE instructor_id = $instructor_id ORDER BY day_id";
$result = mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

if($num_rows > 0)
{
	echo '<p>';
	
	//start table
	echo "<table class=\"postSchedule\">";
	
		//create table row with column ID's
		echo "<tr>";
			echo"<td width='80' style='text-align: left'><b>Day</b></td>";
			echo"<td width='80' style='text-align: center'><b>Start Time</b></td>";
			echo"<td width='80' style='text-align: center'><b>End Time</b></td>";
		echo "</tr>";
		
	//loop to walk through and print to screen all entries in timeslots table
	$row_count = 0;
	while ($row = mysql_fetch_assoc($result)) 
	{
		$row_count++;
		//store each timeslotname and abbreviation in a scalar
		$availability_id=$row["id"];
		$starttime=$row["start_time"];
		$endtime=$row["end_time"];
		$day_of_week=$row["day_id"];
		
		
	
	//generate table row for each timeslot on each iteration of the loop
		echo "<tr";
		if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
		echo ">";
			
			if ($day_of_week == 1)
			{
				$day_of_week = "Monday";
			}
			if ($day_of_week == 2)
			{
				$day_of_week = "Tuesday";
			}
			if ($day_of_week == 3)
			{
				$day_of_week = "Wednesday";
			}
			if ($day_of_week == 4)
			{
				$day_of_week = "Thursday";
			}
			if ($day_of_week == 5)
			{
				$day_of_week = "Friday";
			}
			
			echo "<td style='text-align: left'>$day_of_week</td>";
			echo "<td style='text-align: center'>".date('g:ia', strtotime($starttime))."</td>";		
			echo "<td style='text-align: center'>".date('g:ia', strtotime($endtime))."</td>"; 
			
			echo "<td width='5' style='text-align: center'>";
			
			
			
		echo "<td>";		//cell containing form for edit timeslot link/button
			echo "<a href='edit_timeslots.php?id=$availability_id'>Edit</a>";
		echo "</td>";
		
		echo "<td>";		//cell containing form for delete timeslot link/button
				echo "<a href='delete_timeslots.php?id=$availability_id'>Delete</a>";
			echo "</td>";
	
		echo "</tr>";
		
	}

	//end table tag
	echo "</table>";

	echo '</p>';

}
else
{
	echo "<p><b>NO TIMESLOTS CURRENTLY ASSIGNED TO INSTRUCTOR</b></p>";
}		
			
?>


<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>